package com.sm.auth.controller;

import com.sm.auth.dto.LoginDto;
import com.sm.auth.service.AuthService;
import com.sm.common.constants.HttpStatus;
import com.sm.common.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.InternalAuthenticationServiceException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLOutput;

@RestController
@RequestMapping("auth")
@Slf4j
public class  AuthController {
    @Autowired
    private AuthService authService;
    @Autowired
    private PasswordEncoder passwordEncoder;

    @PostMapping("sys")
    //登录接口
    public Result login(@RequestBody LoginDto loginDto) {
        log.info("用户登录：{}", loginDto);
        String token = authService.login(loginDto);
        return  Result.success( "登录成功!!!", token);
    }

    @GetMapping("test")
//    @PreAuthorize("@ss.hasPermi('system:menu:list')")
    public Result test() {
        String passwordSecret = passwordEncoder.encode("123456");
        System.out.println(passwordSecret);
        return Result.success();
    }
}
